#include "Common.h"
#include "ObjectPool.h"

class PageCache
{
public:
    static PageCache *GetInstance()
    {
        return &_sInstance;
    }

    Span *MapObjectToSpan(void *obj);

    // 获取一个k页的span
    Span *NewSpan(size_t k);
    std::mutex &GetMtx()
    {
        return _Pagemtx;
    }
    //把从Central还回来的内存进行合并的函数
    void ReleaseSpanToPageCache(Span *span);


private:
    PageCache();
    PageCache(const PageCache &) = delete;
    SpanList _spanLists[NPAGES];
    std::mutex _Pagemtx;
    unordered_map<PAGE_ID, Span *> _idSpanMap;
    static PageCache _sInstance;
    ObjectPool<Span> _spanPool;
};